package org.csu.mypetstore.web.servlets;

import com.alibaba.fastjson.JSON;
import org.csu.mypetstore.util.ResultProductList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class PasswordValidServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String newpw = req.getParameter("newpw");
        String repw = req.getParameter("repw");

        ResultProductList result = new ResultProductList();
        resp.setContentType("text/json");
        PrintWriter out = resp.getWriter();

        if(newpw.equals(repw)){
            result.setCode(1);
        }
        else{
            result.setCode(0);
        }

        String rt = JSON.toJSONString(result);
        out.print(rt);

        out.flush();
        out.close();
    }
}
